﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace iLangl.Model
{
	public class ProductsRequestContext : BaseContext
	{
		IList<Product> products = null;

		public override void SetContext(object context)
		{
			base.SetContext(context);
			if (context is IList<Product>)
			{
				products = context as IList<Product>;

			}

		}

		public override object GetContext()
		{
			if (products == null)
				return string.Empty;

			startDocument();
			Write(writer);

			return endDocument();
		}

		public void Write(XmlWriter writer)
		{
			writer.WriteStartElement("Products");


			InitExtendedAttributes(writer, products);
			InitExtendedElements(writer, products);

			foreach (Product product in products)
			{
				writer.WriteStartElement("Product");

				writer.WriteAttributeString("prodId", product.Id);
				writer.WriteAttributeString("prodName", product.Name);

				writer.WriteEndElement();
			}
			writer.WriteEndElement();
		}
	}
}
